package com.qingmi.farmer.data.repository.data;

import com.qingmi.farmer.data.DataSetting;
import com.wjjun.base.data.cache.CacheProviders;
import com.wjjun.base.data.db.DBManager;
import com.wjjun.base.data.db.IDBManager;
import com.qingmi.farmer.data.model.Buyer;
import com.qingmi.farmer.data.model.GrainDemand;
import com.qingmi.farmer.data.model.GrainLevel;
import com.qingmi.farmer.data.model.GrainOrder;
import com.qingmi.farmer.data.model.GrainType;
import com.qingmi.farmer.data.repository.api.GrainApiRepository;
import com.qingmi.farmer.data.request.GetGrainDemandListReq;
import com.qingmi.farmer.data.request.GetGrainOrderReq;
import com.wjjun.base.data.respository.BaseDataRepository;
import com.wjjun.basemvpvm.data.executor.PostExecutionThread;
import com.wjjun.basemvpvm.data.executor.ThreadExecutor;
import com.wjjun.basemvpvm.data.observer.DefaultObserver;
import com.wjjun.basemvpvm.data.request.SimpleRequest;

import java.util.List;

import javax.inject.Inject;

import io.rx_cache2.EvictProvider;

/**
 * 粮食模块
 * Created by 67535 on 2018/5/23.
 */
public class GrainDataRepository extends BaseDataRepository<GrainApiRepository> {

    private IDBManager dbManager;

    @Inject
    public GrainDataRepository(GrainApiRepository apiRepository, ThreadExecutor threadExecutor,
                               PostExecutionThread postExecutionThread,
                               DBManager dbManager, CacheProviders cacheProviders) {

        super(apiRepository, threadExecutor, postExecutionThread, cacheProviders);
        this.dbManager = dbManager;
    }

    /**
     * 获取粮食类型
     */
    public void getGrainTypeList(DefaultObserver<List<GrainType>> observer) {
        execute(cacheProviders.getGrainTypeList(apiRepository.getGrainTypeList(), new EvictProvider(false)), observer);
    }

    /**
     * 获取粮食等级
     */
    public void getGrainLevelList(DefaultObserver<List<GrainLevel>> observer) {
        execute(cacheProviders.getGrainLevelList(apiRepository.getGrainLevelList(), new EvictProvider(false)), observer);
    }

    /**
     * 获取收购商列表
     */
    public void getBuyerList(DefaultObserver<List<Buyer>> observer) {
        execute(cacheProviders.getBuyer(apiRepository.getBuyerList(), new EvictProvider(false)), observer);
    }

    /**
     * 获取农户粮食订单详情
     */
    public void getGrainOrderDetail(DefaultObserver<GrainOrder> observer, SimpleRequest param) {
        execute(apiRepository.getGrainOrderDetail(param), observer);
    }

    /**
     * 获取粮食订单列表
     */
    public void getGrainOrderList(DefaultObserver<List<GrainOrder>> observer, GetGrainOrderReq param) {
        execute(apiRepository.getGrainOrderList(param), observer);
    }

    /**
     * 获取待上报的粮食订单列表
     */
    public void getGrainPendingReportList(DefaultObserver<List<GrainOrder>> observer) {
        getGrainOrderList(observer, new GetGrainOrderReq(DataSetting.GRAIN_ORDER_STATUS_PENDING_REPORTED));
    }

    /**
     * 获取待确认的粮食订单列表
     */
    public void getGrainPendingConfirmList(DefaultObserver<List<GrainOrder>> observer) {
        getGrainOrderList(observer, new GetGrainOrderReq(DataSetting.GRAIN_ORDER_STATUS_PENDING_CONFIRM));
    }

    /**
     * 获取已完成的粮食订单列表
     */
    public void getGrainCompletedList(DefaultObserver<List<GrainOrder>> observer) {
        getGrainOrderList(observer, new GetGrainOrderReq(DataSetting.GRAIN_ORDER_STATUS_COMPLETED));
    }

    /**
     * 收购列表
     */
    public void getGrainDemandList(DefaultObserver<List<GrainDemand>> observer, GetGrainDemandListReq param) {
        execute(apiRepository.getGrainDemandList(param), observer);
    }

    /**
     * 收购详情
     */
    public void getGrainDemandDetail(DefaultObserver<GrainDemand> observer, SimpleRequest param) {
        execute(apiRepository.getGrainDemandDetail(param), observer);
    }


}
